package com.geek.service.impl;

import com.geek.mapper.MarketStorageMapper;
import com.geek.model.MarketStorage;
import com.geek.service.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;

/**
 * @author 小豪
 * @version 1.0
 * @description
 * @date 2024-06-17 18:59
 */
@Service
public class StorageServiceImpl implements StorageService {
    @Autowired
    private MarketStorageMapper storageMapper;
    @Value("${minio.endpoint}")
    private String endpoint;
    @Value("${minio.bucketName}")
    private String bucketName;

    @Override
    public MarketStorage upload(MultipartFile file, String objectName) {
        MarketStorage marketStorage = new MarketStorage();
        long size = file.getSize();
        String contentType = file.getContentType();
        String originalFilename = file.getOriginalFilename();
        Date date = new Date();
        marketStorage.setAddTime(date);
        marketStorage.setUpdateTime(date);
        marketStorage.setKey(objectName);
        marketStorage.setSize((int) size);
        marketStorage.setUrl("http://118.31.5.216:9000/geek-shop/" + objectName);
        marketStorage.setType(contentType);
        marketStorage.setName(originalFilename);
        storageMapper.insertSelective(marketStorage);
        Integer id = marketStorage.getId();
        return storageMapper.selectByPrimaryKey(id);
    }
}
